package com.example.administrator.myapplication;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.nfc.Tag;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.awt.font.TextAttribute;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    TextView mTvResult;
    Button mBtnProgress;
    ProgressDialog progressDialog;
    private void showProgressDialog(){
        progressDialog = new ProgressDialog(this);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AlertDialog dialog = new AlertDialog.Builder(this)
                .setTitle("请选择性别")
                .setPositiveButton("确定",null)
                .setNegativeButton("取消",null)
                .setSingleChoiceItems(new String[]{"男", "女"}, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.e(TAG,"onClick:"+which);

                        TextView tvResult = findViewById(R.id.tv_result);

                        tvResult.setText(which==0?"男":"女");
                    }
                })
                .create();
        dialog.show();

    }

    private void closeProgressDialog() {
        progressDialog.dismiss();
    }

                public void onClick(View v){
            showProgressDialog();
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try{
                        Thread.sleep(5000);
                        closeProgressDialog();
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                }
            });
        }
    }


